from lib.Stepper import Stepper
import time
from setting import *

s2 = Stepper(POWER_PIN_STEPPER_X1_STEP,POWER_PIN_STEPPER_X1_DIR,en_pin=POWER_PIN_STEPPER_X1_ENA,steps_per_rev=400,speed_sps=3200,timer_id=1)
s1 = Stepper(POWER_PIN_STEPPER_Y1_STEP,POWER_PIN_STEPPER_Y1_DIR,en_pin=POWER_PIN_STEPPER_Y1_ENA,steps_per_rev=800,speed_sps=3200,timer_id=2)
#  s1.free_run(360)
# s2.free_run(360)
# s1.speed(4500) #use low speed for the calibration
# s1.free_run(1) #move backwards
# s1.speed(90)
numCircle= 1
s1.speed_rps(numCircle)
s1.target_deg(360*50)

time.sleep(0.1)
s1.speed_rps(2)

time.sleep(0.1)
s1.speed_rps(3)
time.sleep(0.2)
s1.speed_rps(4)
time.sleep(0.3)
s1.speed_rps(5)
time.sleep(0.4)
s1.speed_rps(6)
time.sleep(0.5)
s1.speed_rps(7)
time.sleep(0.6)


time.sleep(2)
s1.speed_rps(7)
time.sleep(0.6)
s1.speed_rps(6)
time.sleep(0.5)
s1.speed_rps(5)
time.sleep(0.4)
s1.speed_rps(4)
time.sleep(0.3)
s1.speed_rps(3)
time.sleep(0.2)
s1.speed_rps(2)
time.sleep(0.1)
s1.speed_rps(1)

# https://github.com/redoxcode/micropython-stepper/tree/main  
#  

# time.sleep(0.01)

# 
# s1.free_run(-1)
# s1.speed(-3000)
# 
# time.sleep(0.01)
# 
# 
#  
# s1.speed(0)
# s1.free_run(1)
# time.sleep(2)
# s1.stop()
#  
# s1.stop() #stop as soon as the switch is triggered
# s1.overwrite_pos(0) #set position as 0 point
# s1.target(0) #set the target to the same value to avoid unwanted movement
# s1.speed(200) #return to default speed
# s1.track_target() #start stepper again
# 
# #calibration finished. Do something else below.
# s1.target_deg(180)
# time.sleep(5.0)
while True:
    print(s1.get_pos())
    print(s1.get_pos_deg())
    time.sleep(1)